package com.zy.thread.saleticket;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/14 9:07
 **/
public class Ticket implements Runnable{
    private int tick=1;
    private Object lock =new Object();
    @Override
    public synchronized void run() {
//        try {
//            Thread.sleep(300);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        synchronized(lock){
            while(true){
                System.out.println(Thread.currentThread().getName()+"进入买票。");
                if(tick>0){
//
                    System.out.println(Thread.currentThread().getName()+"买到车票，tick号为："+ tick--);

                }else {
                    break;
                }
//            }
        }

    }
}
